﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio
{
    /// <summary>
    /// 定义扩展比较类
    /// </summary>
    public static class ExtendEquals
    {
        public static bool AreEqual(this double value1, double value2, double tolerance = 1E-6)
        {
            return (value1 == value2)
                || Math.Abs(value1 - value2) < tolerance;
        }

        public static bool AreEqualsZero(this double value1, double tolerance = 1E-6)
        {
            return (value1 == 0)
                || Math.Abs(value1 - 0) < tolerance;
        }

        public static bool GreaterThan(this double value1, double value2, double tolerance = 1E-6)
        {
            return ((value1 > value2) && !AreEqual(value1, value2, tolerance));
        }

        public static bool GreaterThanOrEqual(this double value1, double value2, double tolerance = 1E-6)
        {
            return (value1 > value2) || AreEqual(value1, value2, tolerance);
        }

        public static bool GreaterThanOrEquals(this double value1, double value2, double tolerance = 1E-6)
        {
            return (value1 > value2) || AreEqual(value1, value2, tolerance);
        }

        public static bool IsZero(this double value, double tolerance = 1E-6)
        {
            return (Math.Abs(value) < tolerance);
        }

        public static bool LessThan(this double value1, double value2, double tolerance = 1E-6)
        {
            return ((value1 < value2) && !AreEqual(value1, value2, tolerance));
        }

        public static bool LessThanOrEqual(this double value1, double value2, double tolerance = 1E-6)
        {
            return (value1 < value2) || AreEqual(value1, value2, tolerance);
        }
        public static bool LessThanOrEquals(this double value1, double value2, double tolerance = 1E-6)
        {
            return (value1 < value2) || AreEqual(value1, value2, tolerance);
        }

        public static bool LessThanOrEqualZero(this double value1, double tolerance = 1E-6)
        {
            return (value1 < 0) || AreEqual(value1, 0, tolerance);
        }

        public static bool GreaterThanZero(this double value1, double tolerance = 1E-6)
        {
            return ((value1 > 0) && !AreEqual(value1, 0, tolerance));
        }

        public static bool GreaterThanOrEqualZero(this double value1, double tolerance = 1E-6)
        {
            return (value1 > 0) || AreEqual(value1, 0, tolerance);
        }


        public static bool LessThanZero(this double value1, double tolerance = 1E-6)
        {
            return ((value1 < 0) && !AreEqual(value1, 0, tolerance));
        }




        public static bool AreEqual(this float value1, float value2, float tolerance = 1E-6f)
        {
            return (value1 == value2)
                || Math.Abs(value1 - value2) < tolerance;
        }

        public static bool GreaterThan(this float value1, float value2, float tolerance = 1E-6f)
        {
            return ((value1 > value2) && !AreEqual(value1, value2, tolerance));
        }
        public static bool GreaterThanZero(this float value1, double tolerance = 1E-6f)
        {
            return ((value1 > 0) && !AreEqual(value1, 0, tolerance));
        }

        public static bool GreaterThanOrEqual(this float value1, float value2, float tolerance = 1E-6f)
        {
            return (value1 > value2) || AreEqual(value1, value2, tolerance);
        }

        public static bool GreaterThanOrEqualZero(this float value1, float tolerance = 1E-6f)
        {
            return (value1 > 0) || AreEqual(value1, 0, tolerance);
        }

        public static bool IsZero(this float value, float tolerance = 1E-6f)
        {
            return (Math.Abs(value) < tolerance);
        }

        public static bool LessThan(this float value1, float value2, float tolerance = 1E-6f)
        {
            return ((value1 < value2) && !AreEqual(value1, value2, tolerance));
        }

        public static bool LessThanZero(this float value1, float tolerance = 1E-6f)
        {
            return ((value1 < 0) && !AreEqual(value1, 0, tolerance));
        }

        public static bool LessThanOrEqual(this float value1, float value2, float tolerance = 1E-6f)
        {
            return (value1 < value2) || AreEqual(value1, value2, tolerance);
        }
        public static bool LessThanOrEqualZero(this float value1, float tolerance = 1E-6f)
        {
            return (value1 < 0) || AreEqual(value1, 0, tolerance);
        }




        public static bool AreEqual(this decimal value1, decimal value2, decimal tolerance = 1E-6m)
        {
            return (value1 == value2)
                || Math.Abs(value1 - value2) < tolerance;
        }

        public static bool GreaterThan(this decimal value1, decimal value2, decimal tolerance = 1E-6m)
        {
            return ((value1 > value2) && !AreEqual(value1, value2, tolerance));
        }

        public static bool GreaterThanZero(this decimal value1, decimal tolerance = 1E-6m)
        {
            return ((value1 > 0) && !AreEqual(value1, 0, tolerance));
        }

        public static bool GreaterThanOrEqual(this decimal value1, decimal value2, decimal tolerance = 1E-6m)
        {
            return (value1 > value2) || AreEqual(value1, value2, tolerance);
        }

        public static bool GreaterThanOrEqualZero(this decimal value1, decimal tolerance = 1E-6m)
        {
            return (value1 > 0) || AreEqual(value1, 0, tolerance);
        }

        public static bool IsZero(this decimal value, decimal tolerance = 1E-6m)
        {
            return (Math.Abs(value) < tolerance);
        }

        public static bool LessThan(this decimal value1, decimal value2, decimal tolerance = 1E-6m)
        {
            return ((value1 < value2) && !AreEqual(value1, value2, tolerance));
        }

        public static bool LessThanZero(this decimal value1, decimal tolerance = 1E-6m)
        {
            return ((value1 < 0) && !AreEqual(value1, 0, tolerance));
        }

        public static bool LessThanOrEqual(this decimal value1, decimal value2, decimal tolerance = 1E-6m)
        {
            return (value1 < value2) || AreEqual(value1, value2, tolerance);
        }
        public static bool LessThanOrEqualZero(this decimal value1, decimal tolerance = 1E-6m)
        {
            return (value1 < 0) || AreEqual(value1, 0, tolerance);
        }
    }
}
